﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IBLL;
using Dtos;
using DAL;
using IDAL;
using Model;

namespace BLL
{
    public class PositionsBll : IPositionsBll
    {
        public IPositionsDal _p;
        public PositionsBll(IPositionsDal p)
        {
            _p = p;
        }
        public async Task<int> AddAsync(string title)
        {
            return await _p.AddAsync(new Model.Positions
            {
                title = title
            });
        }
        public async Task<int> DeleteAsync(Guid id)
        {
            var data = await _p.GetIdAll(id);
            if (data != null)
                return await _p.DeleteAsync(data);
            return 0;
        }
        public async Task<int> EditAsync(Guid id, string title)
        {
            var data = await _p.GetIdAll(id);
            if (data == null)
                return 0;
            data.title = title;
            data.UpdateTime = DateTime.Now;
            return await _p.UpdateAsync(data);
        }

        public Task<int> EditAsync(Guid id, string title, Guid departimentId)
        {
            throw new NotImplementedException();
        }

        public async Task<List<PositionsDost>> getAllPositions()
        {
            var data = await _p.GetAll();
            return data.Select(m => new PositionsDost
            {
                Id = m.Id,

                Title = m.title,
                CreateTime = m.CreateTime,
                UpdateTime = m.UpdateTime,
            }).ToList();
        }
        public Task<PositionsDost> GetPositionsIdAsync(Guid id)
        {
            throw new NotImplementedException();
        }

        public async Task<bool> IsExistsAsync(string title)
        {
            var a = await _p.GetDataByChoose(m => m.title.Equals(title));
            return a.Count() > 0;
        }

     

        
    }
    }

